package com.tianya.controller;

import com.tianya.common.Results;
import com.tianya.domain.dto.ClazzRequestDTO;
import com.tianya.domain.entity.Clazz;
import com.tianya.domain.vo.ClazzVO;
import com.tianya.domain.vo.PageResultVO;
import com.tianya.service.ClazzService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author TianYaGuoKe
 * @date 2025/5/25 22:56
 * @description ClazzController
 */
@Api("班级管理")
@RestController
@RequestMapping("/clazz")
public class ClazzController {
    @Resource
    private ClazzService clazzService;
    @ApiOperation("创建班级")
    @PostMapping
    public Results createClazz(@RequestBody ClazzRequestDTO clazzRequestDTO) {
        clazzService.createClazz(clazzRequestDTO);
        return Results.success();
    }

    @ApiOperation("获取班级列表")
    @GetMapping("/list")
    public Results<List<ClazzVO>> listClazz() {
        List<ClazzVO> clazzVOList = clazzService.listClazz();
        return Results.success(clazzVOList);
    }

    @ApiOperation("分页获取班级")
    @PostMapping("/page")
    public Results<PageResultVO<ClazzVO>> pageClazz(@RequestParam(defaultValue = "1") Integer pageNum,
                                                    @RequestParam(defaultValue = "10") Integer pageSize,
                                                    ClazzRequestDTO clazzRequestDTO) {
        PageResultVO<ClazzVO> pageResultVO = clazzService.pageClazz(pageNum, pageSize, clazzRequestDTO);
        return Results.success(pageResultVO);
    }

    @ApiOperation("查看详情")
    @GetMapping("/{id}")
    public Results<Clazz> getClazz(@PathVariable Long id) {
        Clazz clazz = clazzService.getById(id);
        return Results.success(clazz);
    }

    @ApiOperation("编辑班级")
    @PutMapping
    public Results updateClazz(@RequestBody Clazz clazz) {
        clazzService.updateById(clazz);
        return Results.success();
    }

    @ApiOperation("删除班级")
    @DeleteMapping("/{id}")
    public Results deleteClazz(@PathVariable Long id) {
        clazzService.removeById(id);
        return Results.success();
    }
}
